<?php

/**
 * This is the model class for table "{{ptserviceno}}".
 *
 * The followings are the available columns in table '{{ptserviceno}}':
 * @property string $idptserviceno
 * @property string $caseno
 * @property string $idccward
 * @property string $idpttype
 * @property string $idccsex
 * @property string $idptexsumptor
 * @property string $ownername
 * @property string $owneraddress
 * @property string $propertyno
 * @property string $propertyaddress
 * @property string $constyear
 * @property string $totalplotarea
 * @property string $openplotarea
 * @property string $compplotarea
 * @property integer $transferbreakupflag
 * @property integer $deleteflag
 * @property integer $waterharvesting
 *
 * The followings are the available model relations:
 * @property Bpapplicptservice[] $bpapplicptservices
 * @property Ptdetailarea[] $ptdetailareas
 * @property Ccsex $idccsex0
 * @property Ccward $idccward0
 * @property Ptexsumptor $idptexsumptor0
 * @property Pttype $idpttype0
 * @property Pttransaction[] $pttransactions
 * @property Pttransfer[] $pttransfers
 * @property Wmmaster[] $wmmasters
 */
class Ptserviceno extends CActiveRecord
{
    
        public $test = array();

	/**
	 * Returns the static model of the specified AR class.
	 * @return Ptserviceno the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{ptserviceno}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ownername, owneraddress, propertyno, constyear, transferbreakupflag, deleteflag, waterharvesting', 'required'),
			array('transferbreakupflag, deleteflag, waterharvesting', 'numerical', 'integerOnly'=>true),
			array('caseno, idccward, idpttype, idccsex, idptexsumptor, constyear', 'length', 'max'=>10),
			array('ownername, owneraddress, propertyaddress', 'length', 'max'=>100),
			array('propertyno', 'length', 'max'=>45),
			array('totalplotarea, openplotarea, compplotarea', 'length', 'max'=>15),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idptserviceno, caseno, idccward, idpttype, idccsex, idptexsumptor, ownername, owneraddress, propertyno, propertyaddress, constyear, totalplotarea, openplotarea, compplotarea, transferbreakupflag, deleteflag, waterharvesting', 'safe', 'on'=>'search'),
                        array('idccward, idpttype, idccsex, idptexsumptor', 'validatefkeys'),
		);
	}        
        
        public function validatefkeys($attribute,$params){
               $aux = $attribute . '0';
               if(!$this->$aux)
                    $this->addError($attribute, Yii::t('application', 'Incorrect {attribute}.', array('{attribute}'=>Yii::t('application', $attribute))));
        }      
        
        
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bpapplicptservices' => array(self::HAS_MANY, 'Bpapplicptservice', 'idptserviceno'),
			'ptdetailareas' => array(self::HAS_MANY, 'Ptdetailarea', 'idptserviceno'),
			'idccsex0' => array(self::BELONGS_TO, 'Ccsex', 'idccsex'),
			'idccward0' => array(self::BELONGS_TO, 'Ccward', 'idccward'),
			'idptexsumptor0' => array(self::BELONGS_TO, 'Ptexsumptor', 'idptexsumptor'),
			'idpttype0' => array(self::BELONGS_TO, 'Pttype', 'idpttype'),
			'pttransactions' => array(self::HAS_MANY, 'Pttransaction', 'idptserviceno'),
			'pttransfers' => array(self::HAS_MANY, 'Pttransfer', 'idptserviceno'),
			'wmmasters' => array(self::HAS_MANY, 'Wmmaster', 'idptserviceno'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idptserviceno' => Yii::t('application', 'Idptserviceno'),
			'caseno' => Yii::t('application', 'Caseno'),
			'idccward' => Yii::t('application', 'Idccward'),
			'idpttype' => Yii::t('application', 'Idpttype'),
			'idccsex' => Yii::t('application', 'Idccsex'),
			'idptexsumptor' => Yii::t('application', 'Idptexsumptor'),
			'ownername' => Yii::t('application', 'Ownername'),
			'owneraddress' => Yii::t('application', 'Owneraddress'),
			'propertyno' => Yii::t('application', 'Propertyno'),
			'propertyaddress' => Yii::t('application', 'Propertyaddress'),
			'constyear' => Yii::t('application', 'Constyear'),
			'totalplotarea' => Yii::t('application', 'Totalplotarea'),
			'openplotarea' => Yii::t('application', 'Openplotarea'),
			'compplotarea' => Yii::t('application', 'Compplotarea'),
			'transferbreakupflag' => Yii::t('application', 'Transferbreakupflag'),
			'deleteflag' => Yii::t('application', 'Deleteflag'),
			'waterharvesting' => Yii::t('application', 'Waterharvesting'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idptserviceno',$this->idptserviceno,true);
		$criteria->compare('caseno',$this->caseno,true);
		$criteria->compare('idccward',$this->idccward,true);
		$criteria->compare('idpttype',$this->idpttype,true);
		$criteria->compare('idccsex',$this->idccsex,true);
		$criteria->compare('idptexsumptor',$this->idptexsumptor,true);
		$criteria->compare('ownername',$this->ownername,true);
		$criteria->compare('owneraddress',$this->owneraddress,true);
		$criteria->compare('propertyno',$this->propertyno,true);
		$criteria->compare('propertyaddress',$this->propertyaddress,true);
		$criteria->compare('constyear',$this->constyear,true);
		$criteria->compare('totalplotarea',$this->totalplotarea,true);
		$criteria->compare('openplotarea',$this->openplotarea,true);
		$criteria->compare('compplotarea',$this->compplotarea,true);
		$criteria->compare('transferbreakupflag',$this->transferbreakupflag);
		$criteria->compare('deleteflag',$this->deleteflag);
		$criteria->compare('waterharvesting',$this->waterharvesting);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}